package zuoye_3_10;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//7.我们使用[0-9] [a-z][A-Z]范围内来表示字符串
//示例1：
//输入ppRYYGrrYBR2258
//p-2
////R-2
//Y-1
//G-1
////r-2
////R-2
//2-2
//5-1
////8-1
//B-1
//	YrR8RrY
////Y-2
////r-2
////R-2
////8-1
//输出：
//Yes 8
//
//
//	输入:ppRYYGrrYB225
//	YrR8RrY
//NO
public class Zuoye_7 {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一个字符串：");
        String str1 = sc.nextLine();
        System.out.println("请输入第二个字符串：");
        String str2 = sc.nextLine();
        int remaining = isMatch(str1, str2);
        if (remaining >= 0) {
            System.out.println("Yes " + remaining);
        } else {
            System.out.println("No");
        }
        sc.close();
    }

    public static int isMatch(String str1, String str2) {
        HashMap<Character, Integer> map1 = getCharCount(str1);
        HashMap<Character, Integer> map2 = getCharCount(str2);
        for (Map.Entry<Character, Integer> entry : map2.entrySet()) {
            if (!map1.containsKey(entry.getKey()) || map1.get(entry.getKey()) < entry.getValue()) {
                return -1;
            }
            map1.put(entry.getKey(), map1.get(entry.getKey()) - entry.getValue());
        }
        int remaining = 0;
        for (int count : map1.values()) {
            remaining += count;
        }
        return remaining;
    }

    public static HashMap<Character, Integer> getCharCount(String str) {
        HashMap<Character, Integer> map = new HashMap<>();
        for (char c : str.toCharArray()) {
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        return map;
    }
}
